package bootstrap

import (
    "gorm.io/gorm"
    "log"
    "wwgin/config"
    "wwgin/global/variable"
    "wwgin/module/gorm_v2"
    "wwgin/module/sys_log_hook"
    "wwgin/module/validation"
    "wwgin/module/zap_factory"
)

//程序初始化,加载配置信息
func LoadConf() {
    //初始化全局的mysql
    var err error
    variable.SqlDB = map[string]*gorm.DB{} //初始化
    for k, _ := range config.MysqlConfMap {
        mysql, err := gorm_v2.GetSqlDriver(k)
        if err != nil {
            log.Fatal(k + "的mysql初始化失败")
        }
        variable.SqlDB[k] = mysql
    }
    //初始化全局日志
    variable.ZapLog = zap_factory.CreateZapFactory(sys_log_hook.ZapLogHandler)
    //初始化全局参数验证翻译器
    err = validation.TransInit("zh")
    if err != nil {
        log.Fatal("翻译器初始化失败")
    }
}
